import json
from collections import Counter

with open('jobs.json') as f:
    data = json.loads(f.read())

title = {}
exp = {}
edu = {}
location = {}
total = 0
for d in data:
    t = d['title'].strip()
    try:
        n = int(d['num'].strip())
    except:
        n = 3
    try:
        title[t] += n
    except:
        title[t] = n
    total += n

    e = d['exp'].strip().split(',')[0]
    if '不限' in e:
        e = '不限'

    ed = d['edu'].strip()
    if '不限' in ed:
        ed = '不限'

    try:
        s = int(d['salary'].replace('元', '').strip().split('-')[0])
    except:
        s = 0
    if s > 0:
        try:
            exp[e][0] += s * n
            exp[e][1] += n
        except:
            exp[e] = [s * n, n]

        try:
            edu[ed][0] += s * n
            edu[ed][1] += n
        except:
            edu[ed] = [s * n, n]

    lc = d['location'].split()
    try:
        lc = lc[1]
    except:
        lc = lc[0]
    try:
        location[lc] += n
    except:
        location[lc] = n

most_title = Counter(title).most_common(10)
rest = total
for t in most_title:
    # print('{name:"%s", value:%s},' % t)
    rest -= int(t[1])
# print('{name:"其他", value:%d}' % rest)

# for e in exp:
#     print(e, exp[e][0]/exp[e][1])

# print(edu)
# for e in edu:
#     print(e, edu[e][0]/edu[e][1])

for l in location:
    print('{name:"%s", value:%s},' % (l, location[l]))
